package com.swotxu.oldwebproject.web.pojo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.NamedThreadLocal;

/**
 * 线程持有的 userinfo
 *
 * @Date: 2019/12/18 18 10:01
 * @Author: swotXu
 */
public class ConcurrentUser {
    private static final Logger log = LoggerFactory.getLogger(ConcurrentUser.class);

    private final static ThreadLocal<UserInfo> concurrentUser = new NamedThreadLocal<>("UserInfoHolder");

    public static void set(UserInfo userInfo){
        log.info("[set] concurrentThread:{}, concurrentUser:{}",Thread.currentThread().getName(), userInfo);
        concurrentUser.set(userInfo);
    }

    public static UserInfo get(){
        log.info("[get] concurrentThread:{}, concurrentUser:{}",Thread.currentThread().getName(), concurrentUser.get());
        return concurrentUser.get();
    }

    public static void remove(){
        log.info("[remove] concurrentThread:{}, concurrentUser:{}",Thread.currentThread().getName(), concurrentUser.get());
        concurrentUser.remove();
    }
}
